package com.example.config;

import com.example.aop.FlowControlInterceptor;
import com.example.aop.IdempotentInterceptor;
import com.example.service.impl.CorsInterceptor;
import com.example.service.impl.MyInterceptor;
import com.example.service.posthandler.RequestAttrHandlerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * webMvc配置
 * @author long
 * @date 2024/12/12 11:39
 */
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {

//    @Resource
//    private MyInterceptor myInterceptor;

    @Resource
    private CorsInterceptor corsInterceptor;

    @Resource
    private IdempotentInterceptor idempotentInterceptor;

    @Resource
    private FlowControlInterceptor flowControlInterceptor;

    @Resource
    private RequestAttrHandlerInterceptor requestAttrHandlerInterceptor;

    /**
     * 所有包含@RestController注解的类 加前缀路径 /api
     * @param configurer
     */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
//        configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class));
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 将自定义拦截器丢到注册缓存
//        registry.addInterceptor(idempotentInterceptor);
//        registry.addInterceptor(flowControlInterceptor);
//        registry.addInterceptor(myInterceptor);
//        registry.addInterceptor(corsInterceptor);

        registry.addInterceptor(requestAttrHandlerInterceptor);

    }


}
